From 086ac6b5c2e9de23b3f71182d80e3f656897b93a Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 21 Apr 2005 10:15:23 +0000 Subject: [PATCH] bitkeeper revision 1.1351 (42677d3b7Caqgw-mG40oawn1nybJ4A) Fix segment save/restore during context switching on x86/64. Signed-off-by: Keir Fraser --- xen/arch/x86/domain.c | 26 +++++++++++++------------- xen/include/asm-x86/x86_32/regs.h | 3 +++ xen/include/asm-x86/x86_64/regs.h | 4 ++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 1cd03bcd47..c89b175fe1 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -632,17 +632,17 @@ static void load_segments(struct exec_domain *p, struct exec_domain *n) else regs->cs &= ~3; - if ( put_user(regs->ss, rsp- 1) | - put_user(regs->rsp, rsp- 2) | - put_user(regs->rflags, rsp- 3) | - put_user(regs->cs, rsp- 4) | - put_user(regs->rip, rsp- 5) | - put_user(regs->gs, rsp- 6) | - put_user(regs->fs, rsp- 7) | - put_user(regs->es, rsp- 8) | - put_user(regs->ds, rsp- 9) | - put_user(regs->r11, rsp-10) | - put_user(regs->rcx, rsp-11) ) + if ( put_user(regs->ss, rsp- 1) | + put_user(regs->rsp, rsp- 2) | + put_user(regs->rflags, rsp- 3) | + put_user(regs->cs, rsp- 4) | + put_user(regs->rip, rsp- 5) | + put_user(n->arch.user_ctxt.gs, rsp- 6) | + put_user(n->arch.user_ctxt.fs, rsp- 7) | + put_user(n->arch.user_ctxt.es, rsp- 8) | + put_user(n->arch.user_ctxt.ds, rsp- 9) | + put_user(regs->r11, rsp-10) | + put_user(regs->rcx, rsp-11) ) { DPRINTK("Error while creating failsafe callback frame.\n"); domain_crash(); @@ -737,7 +737,7 @@ static void __context_switch(void) { memcpy(&p->arch.user_ctxt, stack_ec, - sizeof(*stack_ec)); + CTXT_SWITCH_STACK_BYTES); unlazy_fpu(p); CLEAR_FAST_TRAP(&p->arch); save_segments(p); @@ -747,7 +747,7 @@ static void __context_switch(void) { memcpy(stack_ec, &n->arch.user_ctxt, - sizeof(*stack_ec)); + CTXT_SWITCH_STACK_BYTES); /* Maybe switch the debug registers. */ if ( unlikely(n->arch.debugreg[7]) ) diff --git a/xen/include/asm-x86/x86_32/regs.h b/xen/include/asm-x86/x86_32/regs.h index 865a385b94..0e2e8622a4 100644 --- a/xen/include/asm-x86/x86_32/regs.h +++ b/xen/include/asm-x86/x86_32/regs.h @@ -15,4 +15,7 @@ #define PERMIT_SOFTINT(_dpl, _e, _r) \ ((_dpl) >= (VM86_MODE(_r) ? 3 : ((_r)->cs & 3))) +/* Number of bytes of on-stack execution state to be context-switched. */ +#define CTXT_SWITCH_STACK_BYTES (sizeof(execution_context_t)) + #endif diff --git a/xen/include/asm-x86/x86_64/regs.h b/xen/include/asm-x86/x86_64/regs.h index 355e0fa321..c476282f2d 100644 --- a/xen/include/asm-x86/x86_64/regs.h +++ b/xen/include/asm-x86/x86_64/regs.h @@ -15,4 +15,8 @@ #define PERMIT_SOFTINT(_dpl, _e, _r) \ ((_dpl) >= (KERNEL_MODE(_e, _r) ? 1 : 3)) +/* Number of bytes of on-stack execution state to be context-switched. */ +/* NB. Segment registers and bases are not saved/restored on x86/64 stack. */ +#define CTXT_SWITCH_STACK_BYTES (offsetof(execution_context_t, es)) + #endif -- 2.30.2